import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/xcbd/xcbdSalesContract/list',
  save='/xcbd/xcbdSalesContract/add',
  edit='/xcbd/xcbdSalesContract/edit',
  deleteOne = '/xcbd/xcbdSalesContract/delete',
  deleteBatch = '/xcbd/xcbdSalesContract/deleteBatch',
  importExcel = '/xcbd/xcbdSalesContract/importExcel',
  exportXls = '/xcbd/xcbdSalesContract/exportXls',
  xcbdCollectionRecordList = '/xcbd/xcbdSalesContract/listXcbdCollectionRecordByMainId',
  xcbdCollectionRecordSave='/xcbd/xcbdSalesContract/addXcbdCollectionRecord',
  xcbdCollectionRecordEdit='/xcbd/xcbdSalesContract/updateReceiptStatus',
  xcbdCollectionRecordDelete = '/xcbd/xcbdSalesContract/deleteXcbdCollectionRecord',
  xcbdCollectionRecordDeleteBatch = '/xcbd/xcbdSalesContract/deleteBatchXcbdCollectionRecord',
  xcbdWorkflowList = '/xcbd/xcbdSalesContract/listXcbdWorkflowByMainId',
  xcbdWorkflowSave='/xcbd/xcbdSalesContract/addXcbdWorkflow',
  xcbdWorkflowEdit='/xcbd/xcbdSalesContract/editXcbdWorkflow',
  xcbdWorkflowDelete = '/xcbd/xcbdSalesContract/deleteXcbdWorkflow',
  xcbdWorkflowDeleteBatch = '/xcbd/xcbdSalesContract/deleteBatchXcbdWorkflow',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}
/**
 * 列表接口
 * @param params
 */
export const xcbdCollectionRecordList = (params) => {
  if(params['salesContractId']){
    return defHttp.get({url: Api.xcbdCollectionRecordList, params});
  }
  return Promise.resolve({});
}


/**
 * 删除单个
 */
export const xcbdCollectionRecordDelete = (params,handleSuccess) => {
  return defHttp.delete({url: Api.xcbdCollectionRecordDelete, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const xcbdCollectionRecordDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.xcbdCollectionRecordDeleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const  xcbdCollectionRecordSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.xcbdCollectionRecordEdit : Api.xcbdCollectionRecordSave;
  return defHttp.post({url: url, params});
}
/**
 * 导入
 */
export const xcbdCollectionRecordImportUrl = '/xcbd/xcbdSalesContract/importXcbdCollectionRecord'

/**
 * 导出
 */
export const xcbdCollectionRecordExportXlsUrl = '/xcbd/xcbdSalesContract/exportXcbdCollectionRecord'
/**
 * 列表接口
 * @param params
 */
export const xcbdWorkflowList = (params) => {
  if(params['workOrderId']){
    return defHttp.get({url: Api.xcbdWorkflowList, params});
  }
  return Promise.resolve({});
}


/**
 * 删除单个
 */
export const xcbdWorkflowDelete = (params,handleSuccess) => {
  return defHttp.delete({url: Api.xcbdWorkflowDelete, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const xcbdWorkflowDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.xcbdWorkflowDeleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const  xcbdWorkflowSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.xcbdWorkflowEdit : Api.xcbdWorkflowSave;
  return defHttp.post({url: url, params});
}
/**
 * 导入
 */
export const xcbdWorkflowImportUrl = '/xcbd/xcbdSalesContract/importXcbdWorkflow'

/**
 * 导出
 */
export const xcbdWorkflowExportXlsUrl = '/xcbd/xcbdSalesContract/exportXcbdWorkflow'
